package com.ruoyi.web.entity.db;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.core.entity.BaseMap;
import com.ruoyi.core.entity.SortByType;
import com.ruoyi.core.entity.SortInfo;
import lombok.Data;

import java.util.List;

@Data
public class QueryCreator extends Creator {

    private List<SortInfo> sorts;

    public QueryCreator() {
    }

    public QueryCreator(BaseMap queryData) {
        super(queryData);
    }

    public static <T> void orderBy(QueryWrapper<T> qw, List<SortInfo> sorts) {
        if (sorts != null && sorts.size() > 0) {
            for (SortInfo sort : sorts) {
                if (SortByType.asc.equals(sort.getSortBy())) {
                    qw.orderByAsc(resolveColumnName(sort.getSortName()));
                } else if (SortByType.desc.equals(sort.getSortBy())) {
                    qw.orderByDesc(resolveColumnName(sort.getSortName()));
                }
            }
        }
    }

}
